$PBExportHeader$socket.sru
$PBExportComments$Export By Shu<KenShu@163.net>
forward
global type socket from nonvisualobject
end type

end forward

global type socket from nonvisualobject

end type
global socket socket

type variables
socketraw s
uint socknum=0
integer sock_stream=1
integer sock_dgram=2
integer af_inet=2
integer pf_inet=2
integer iproto=0
integer so_type=4104
integer ipproto_tcp=6
integer ipproto_udp=17
integer sol_socket=-1

end variables



forward prototypes
/*Warning: function integer access: 51*/function getpeername (ulong uladdr,integer iport)
Public function uint accept (ulong uladdr,integer iport)
Public function integer bind (ulong uladdr,integer iport)
Public function integer closesocket ()
Public function uint getsocketnumber ()
Public function integer getsockname (ulong uladdr,integer iport)
Public function integer getsockopt (integer level,integer optname,integer optvalint,linger optvallinger)
Public subroutine initsocket (uint uisnum)
Public function integer ioctlsocket (long cmd,ulong argp)
Public function integer listen (integer backlog)
Public function integer recv (blob buf,integer len,integer flags)
Public function integer recvfrom (blob buf,integer len,integer flags,ulong uladdr,integer iport)
Public function integer send (blob buf,integer len,integer flags)
Public function integer sendto (blob buf,integer len,integer flags,ulong uladdr,integer iport)
Public function integer setsockopt (integer level,integer optname,integer optvalint,linger optvallinger)
Public function integer shutdown (integer how)
Public function uint socket (integer isockettype)
Public function integer wsaasyncselect (uint hwnd,uint wmsg,long levent)
Public function integer wsconnect (ulong ul_addr,integer iport)
end prototypes
/*Warning: function integer access: 51*/function getpeername (ulong uladdr,integer iport);///*Warning: Unknow access: 51*/function getpeername (ulong uladdr,integer iport) returns integer
//ulong uladdr=0
//integer iport=0
integer iret=0


iret = THIS.s.wsgetpeername(THIS.socknum,uladdr,iport)
RETURN iret

end function
Public function uint accept (ulong uladdr,integer iport);//Public function accept (ulong uladdr,integer iport) returns uint
//ulong uladdr=0
//integer iport=0
uint uisocket=0


uisocket = THIS.s.wsaccept(THIS.socknum,uladdr,iport)
RETURN uisocket

end function
Public function integer bind (ulong uladdr,integer iport);//Public function bind (ulong uladdr,integer iport) returns integer
//ulong uladdr=0
//integer iport=0
integer iret=0


iret = THIS.s.wsbind(THIS.socknum,uladdr,iport,THIS.iproto)
RETURN iret

end function
Public function integer closesocket ();//Public function closesocket (none) returns integer
integer iret=0


iret = THIS.s.wsclosesocket(THIS.socknum)
RETURN iret

end function
Public function uint getsocketnumber ();//Public function getsocketnumber (none) returns uint


RETURN THIS.socknum

end function
Public function integer getsockname (ulong uladdr,integer iport);//Public function getsockname (ulong uladdr,integer iport) returns integer
//ulong uladdr=0
//integer iport=0
integer iret=0


iret = THIS.s.wsgetsockname(THIS.socknum,uladdr,iport)
RETURN iret

end function
Public function integer getsockopt (integer level,integer optname,integer optvalint,linger optvallinger);//Public function getsockopt (integer level,integer optname,integer optvalint,linger optvallinger) returns integer
//integer level=0
//integer optname=0
//integer optvalint=0
//linger optvallinger
integer iret=0


iret = THIS.s.wsgetsockopt(THIS.socknum,level,optname,optvalint,optvallinger)
RETURN iret

end function
Public subroutine initsocket (uint uisnum);//Public function initsocket (uint uisnum) returns (none)
//uint uisnum=0
linger lingtmp
integer itmp=0


THIS.socknum = uisnum
THIS.getsockopt(THIS.sol_socket,THIS.so_type,itmp,lingtmp)
IF itmp = THIS.sock_stream THEN //8
	THIS.iproto = THIS.ipproto_tcp
ELSEIF itmp = THIS.sock_dgram THEN
	THIS.iproto = THIS.ipproto_udp
END IF //8

end subroutine
Public function integer ioctlsocket (long cmd,ulong argp);//Public function ioctlsocket (long cmd,ulong argp) returns integer
//long cmd=0
//ulong argp=0
integer iret=0


iret = THIS.s.wsioctlsocket(THIS.socknum,cmd,argp)
RETURN iret

end function
Public function integer listen (integer backlog);//Public function listen (integer backlog) returns integer
//integer backlog=0
integer iret=0


iret = THIS.s.wslisten(THIS.socknum,backlog)
RETURN iret

end function
Public function integer recv (blob buf,integer len,integer flags);//Public function recv (blob buf,integer len,integer flags) returns integer
//blob buf
//integer len=0
//integer flags=0
integer iret=0


iret = THIS.s.wsrecv(THIS.socknum,buf,len,flags)
RETURN iret

end function
Public function integer recvfrom (blob buf,integer len,integer flags,ulong uladdr,integer iport);//Public function recvfrom (blob buf,integer len,integer flags,ulong uladdr,integer iport) returns integer
//blob buf
//integer len=0
//integer flags=0
//ulong uladdr=0
//integer iport=0
integer iret=0


iret = THIS.s.wsrecvfrom(THIS.socknum,buf,len,flags,uladdr,iport)
RETURN iret

end function
Public function integer send (blob buf,integer len,integer flags);//Public function send (blob buf,integer len,integer flags) returns integer
//blob buf
//integer len=0
//integer flags=0
integer iret=0


iret = THIS.s.wssend(THIS.socknum,buf,len,flags)
RETURN iret

end function
Public function integer sendto (blob buf,integer len,integer flags,ulong uladdr,integer iport);//Public function sendto (blob buf,integer len,integer flags,ulong uladdr,integer iport) returns integer
//blob buf
//integer len=0
//integer flags=0
//ulong uladdr=0
//integer iport=0
integer iret=0


iret = THIS.s.wssendto(THIS.socknum,buf,len,flags,uladdr,iport)
RETURN iret

end function
Public function integer setsockopt (integer level,integer optname,integer optvalint,linger optvallinger);//Public function setsockopt (integer level,integer optname,integer optvalint,linger optvallinger) returns integer
//integer level=0
//integer optname=0
//integer optvalint=0
//linger optvallinger
integer iret=0


iret = THIS.s.wssetsockopt(THIS.socknum,level,optname,optvalint,optvallinger)
RETURN iret

end function
Public function integer shutdown (integer how);//Public function shutdown (integer how) returns integer
//integer how=0
integer iret=0


iret = THIS.s.wsshutdown(THIS.socknum,how)
RETURN iret

end function
Public function uint socket (integer isockettype);//Public function socket (integer isockettype) returns uint
//integer isockettype=0


THIS.socknum = THIS.s.wssocket(THIS.pf_inet,isockettype,0)
IF isockettype = THIS.sock_stream THEN //6
	THIS.iproto = 6
ELSEIF isockettype = THIS.sock_dgram THEN
	THIS.iproto = 17
END IF //6
RETURN THIS.socknum

end function
Public function integer wsaasyncselect (uint hwnd,uint wmsg,long levent);//Public function wsaasyncselect (uint hwnd,uint wmsg,long levent) returns integer
//uint hwnd=0
//uint wmsg=0
//long levent=0
integer itmp=0


itmp = THIS.s.wswsaasyncselect(THIS.socknum,hwnd,wmsg,levent)
RETURN itmp

end function
Public function integer wsconnect (ulong ul_addr,integer iport);//Public function wsconnect (ulong ul_addr,integer iport) returns integer
//ulong ul_addr=0
//integer iport=0
integer iret=0


iret = THIS.s.wsconnect(THIS.socknum,ul_addr,iport)
RETURN iret

end function
event constructor;//constructor (none) returns long [pbm_constructor]


THIS.s = CREATE socketraw
RETURN

end event

on socket.create
//create (none) returns (none)


THIS.triggerevent("constructor")

end on

on socket.destroy
//destroy (none) returns (none)


THIS.triggerevent("destructor")

end on

event destructor;//destructor (none) returns long [pbm_destructor]


DESTROY THIS.s
RETURN

end event

